unit mdTPulser_u;

interface

uses
  System.SysUtils, System.Classes, Vcl.ExtCtrls, Vcl.ImgList, Vcl.Controls,
  Vcl.Menus, System.Actions, Vcl.ActnList, Forms;

type
  TTermPulser = class(TThread)
    protected
    procedure Execute; override;
    procedure AtualizaLabels;
  end;

  TmdTPulser = class(TDataModule)
    tiTray: TTrayIcon;
    ImageList1: TImageList;
    PopTray: TPopupMenu;
    AcPulser: TActionList;
    AcLogon: TAction;
    N1LogarUsurio1: TMenuItem;
    BalloonHint1: TBalloonHint;
    AcComandList: TAction;
    AcSair: TAction;
    N2ListaComandos1: TMenuItem;
    N2Sair1: TMenuItem;
    AcMinimizar: TAction;
    N4Sair1: TMenuItem;
    AcPCList: TAction;
    N1: TMenuItem;
    procedure DataModuleCreate(Sender: TObject);
    procedure AcLogonExecute(Sender: TObject);
    procedure AcSairExecute(Sender: TObject);
    procedure AcMinimizarExecute(Sender: TObject);
    procedure tiTrayClick(Sender: TObject);
    procedure AcPCListExecute(Sender: TObject);
  private
    Pulse : TTermPulser;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  mdTPulser: TmdTPulser;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

uses mdsrv_u, uFunctions, gVars_u, uLogin, uAcertaCliente, uChamadosZuma,
  uDiag_IpRange, uDiag_NomeMaq, uDosCMD, uInicio, uMaquinas, uMDZuma,
  uPesqRedeDominio, uPesqTecnicos, uRedesDominios, uTecnicos, uPCList;

{$R *.dfm}

procedure TmdTPulser.AcLogonExecute(Sender: TObject);
begin
Application.ShowMainForm := True;
Login_F.Show;
Login_F.BringToFront;


end;

procedure TmdTPulser.AcMinimizarExecute(Sender: TObject);
begin
   if Application.ShowMainForm then
      p_MinimizaTray;
end;

procedure TmdTPulser.AcPCListExecute(Sender: TObject);
begin
  PCList_F := TPCList_F.Create(Application);
  PCList_F.ShowModal;
end;

procedure TmdTPulser.AcSairExecute(Sender: TObject);
begin

  if Diag_NomeMaq_F <> Nil then
    Diag_NomeMaq_F.Close;

  if Diag_IpRange_F <> Nil then
    Diag_IpRange_F.Close;


  if Maquinas_F <> Nil then
    Maquinas_F.Close;

  if Support_F <> Nil then
    Support_F.Close;

  if Tecnicos_F <> Nil then
    Tecnicos_F.Close;







  vgUsuario.FecharSistema := True;
  Login_F.Close;

end;

procedure TmdTPulser.DataModuleCreate(Sender: TObject);
begin

  StartDados;
  CadMaquina;

  Pulse := TTermPulser.Create(True);
  Pulse.Priority:= tpLower;
  Pulse.Resume;

  Login_F := TLogin_F.Create(Self);
  Login_F.tMinimize.Enabled := True;
  Login_F.Show;
  Login_F.Hide;

end;

procedure TmdTPulser.tiTrayClick(Sender: TObject);
begin

end;

{ TTermPulser }

procedure TTermPulser.AtualizaLabels;
begin

end;

procedure TTermPulser.Execute;
var i: Smallint;
begin
  inherited;
  i:=0;

  while True do
   Begin
      if not piNg('10.10.10.8') then
        continue;

      try
        ConnectServ;
      except
        Sleep(10000);
        mdTPulser.tiTray.IconIndex := 1;
        Continue;
      end;

      Application.ProcessMessages;
      mdsrv.Qry.Close;
      mdsrv.Qry.SQL.Text := 'UPDATE MAQUINAS SET MAQ_UPDPULSER = CURRENT_TIMESTAMP WHERE MAQ_ID = '+QuotedStr(vgMaquina.Maq_ID);
      mdsrv.Qry.Prepare;
      mdsrv.Qry.Open;
      CommitServ;

      if i=0 then
        Begin
          mdTPulser.tiTray.IconIndex := 2;
          mdTPulser.tiTray.BalloonTitle:='SupportTI';
          mdTPulser.tiTray.BalloonHint:='Conected - ['+mdsrv.IBDatabase1.DatabaseName+']';
          mdTPulser.tiTray.BalloonFlags:=bfInfo;
          mdTPulser.tiTray.ShowBalloonHint;
          I:= 1;
          Sleep(20000);
          Synchronize(AtualizaLabels);
          Continue;
        End;

      if Odd(i) then
        mdTPulser.tiTray.IconIndex := 4
      else
        mdTPulser.tiTray.IconIndex := 2;



      I:= 1;
      Sleep(20000);
      Synchronize(AtualizaLabels);
   End;

end;

end.
